package com.laomuji.android.mvvm.demo.web

import com.laomuji.android.mvvm.base.BaseActivity
import com.laomuji.android.mvvm.databinding.ActivityHttpBinding

/**
 * Http页面
 * 看日志,tag_http
 * @author laomuji666
 * @since 2024/3/28
 */
class HttpActivity:BaseActivity<ActivityHttpBinding,HttpViewModel>() {
    override fun initView() {
        viewBinding.btnGetFacebookEvent.setOnClickListener {
            viewModel.facebookEvent(this,"123456789","firstOpen"){
                if(it){
                    viewBinding.etText.setText("埋点成功")
                }else{
                    viewBinding.etText.setText("埋点失败")
                }
            }
        }
        viewBinding.btnPostFrom.setOnClickListener {
            viewModel.postFrom(this,1,"asdahshd@qq.com")
        }
        viewBinding.btnPostJson.setOnClickListener {
            viewModel.postJson(this,1,"asdhjas@qq.com")
        }
        viewBinding.btnPostEncodeBase64.setOnClickListener {
            viewModel.postEncode(this,1,"dsghosdh@qq.com")
        }
    }

    override fun initData() {
        viewModel.uploadALiOssLiveData.observe(this){
            //阿里Oss是否上传成功,运行在主线程
            viewBinding.etText.setText("$it")
        }
        viewModel.uploadFilesLiveData.observe(this){
            //批量上传文件的结果,运行在主线程
            viewBinding.etText.setText(it)
        }
    }
}